#!/bin/bash
#
# aim: install singal tomcat
# date: 9-29-2021
 
 
 
tar xzf /home/app/tomcat/apache-tomcat-9.0.53.tar.gz -C /data
tar xzf /home/app/tomcat/jdk-8u301-linux-x64.tar.gz -C /data
echo "export JAVA_HOME=/data/jdk1.8.0_301
export JRE_HOME=/data/jdk1.8.0_301/jre
export CLASSPATH=.:\$JAVA_HOME/lib:\$JRE_HOME/lib:\$CLASSPATH
export PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH" >> /etc/profile
source /etc/profile
java -version
 
cat <<EOF > /data/apache-tomcat-9.0.53//bin/setenv.sh
CATALINA_PID="\$CATALINA_BASE/tomcat.pid"
JAVA_OPTS="-server -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=1024m -Xms1024M -Xmx2048M -XX:MaxNewSize=256m"
EOF
 
chmod a+x /data/apache-tomcat-9.0.53//bin/setenv.sh
 
cat <<EOF > /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
 
Environment="JAVA_HOME=/data/jdk1.8.0_301"
Environment="CATALINA_HOME=/data/apache-tomcat-9.0.53"
 
PIDFile=/data/apache-tomcat-9.0.53/tomcat.pid
ExecStart=/data/apache-tomcat-9.0.53/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
EOF
 
systemctl daemon-reload
systemctl start tomcat.service
systemctl enable tomcat.service
systemctl disable tomcat.service
systemctl status tomcat.service
 
systemctl stop firewalld
systemctl disable firewalld
 
curl -I 127.0.0.1:8080
